home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / jackal.c < prev    next >
C/C++ Source or Header  |  1999-12-22  |  12KB  |  492 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Written by Kenneth Lin (kenneth_lin@ai.vancouver.bc.ca)
  6.  
  7.   Functions to emulate the video hardware of the machine.
  8.  
  9. ***************************************************************************/
  10.  
  11. #include "driver.h"
  12. #include "vidhrdw/generic.h"
  13.  
  14. unsigned char *jackal_scrollram,*jackal_videoctrl;
  15.  
  16.  
  17.  
  18. void jackal_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  19. {
  20.     int i;
  21.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  22.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  23.  
  24.  
  25.     for (i = 0;i < TOTAL_COLORS(1);i++)
  26.     {
  27.         COLOR(1,i) = (*color_prom & 0x0f);
  28.         color_prom++;
  29.     }
  30.     for (i = 0;i < TOTAL_COLORS(2);i++)
  31.     {
  32.         COLOR(2,i) = (*color_prom & 0x0f) + 16;
  33.         color_prom++;
  34.     }
  35. }
  36.  
  37.  
  38.  
  39. int jackal_vh_start(void)
  40. {
  41.     videoram_size = 0x400;
  42.  
  43.     dirtybuffer = 0;
  44.     tmpbitmap = 0;
  45.  
  46.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  47.     {
  48.         return 1;
  49.     }
  50.     memset(dirtybuffer,1,videoram_size);
  51.     if ((tmpbitmap = osd_new_bitmap(Machine->drv->screen_width,Machine->drv->screen_height,Machine->scrbitmap->depth)) == 0)
  52.     {
  53.         free(dirtybuffer);
  54.         return 1;
  55.     }
  56.     return 0;
  57. }
  58.  
  59.  
  60. void jackal_vh_stop(void)
  61. {
  62.     free(dirtybuffer);
  63.     osd_free_bitmap(tmpbitmap);
  64.  
  65.     dirtybuffer = 0;
  66.     tmpbitmap = 0;
  67. }
  68.  
  69.  
  70.  
  71. /***************************************************************************
  72.  
  73.   Draw the game screen in the given osd_bitmap.
  74.   Do NOT call osd_update_display() from this function, it will be called by
  75.   the main emulation engine.
  76.  
  77. ***************************************************************************/
  78. void jackal_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  79. {
  80.     unsigned char *sr, *ss;
  81.     int offs,i;
  82.     unsigned char *RAM = (memory_region(REGION_CPU1));
  83.  
  84.  
  85.     if (palette_recalc())
  86.     {
  87.         memset(dirtybuffer,1,videoram_size);
  88.     }
  89.  
  90.     jackal_scrollram = &RAM[0x0020];
  91.     colorram = &RAM[0x2000];
  92.     videoram = &RAM[0x2400];
  93.  
  94.     spriteram_size = 0x500;
  95.  
  96.     if (jackal_videoctrl[0x03] & 0x08)
  97.     {
  98.         sr = &RAM[0x03800];    // Sprite 2
  99.         ss = &RAM[0x13800];    // Additional Sprite 2
  100.     }
  101.     else
  102.     {
  103.         sr = &RAM[0x03000];    // Sprite 1
  104.         ss = &RAM[0x13000];    // Additional Sprite 1
  105.     }
  106.  
  107.     /* for every character in the Video RAM, check if it has been modified */
  108.     /* since last time and update it accordingly. */
  109.     for (offs = videoram_size - 1;offs >= 0;offs--)
  110.     {
  111.         if (dirtybuffer[offs])
  112.         {
  113.             int sx,sy;
  114.  
  115.             dirtybuffer[offs] = 0;
  116.  
  117.             sx = offs % 32;
  118.             sy = offs / 32;
  119.  
  120.             drawgfx(tmpbitmap,Machine->gfx[0],
  121.                 videoram[offs] + ((colorram[offs] & 0xc0) << 2) + ((colorram[offs] & 0x30) << 6),
  122.                 0,//colorram[offs] & 0x0f, there must be a PROM like in Contra
  123.                 colorram[offs] & 0x10,colorram[offs] & 0x20,
  124.                 8*sx,8*sy,
  125.                 0,TRANSPARENCY_NONE,0);
  126.         }
  127.     }
  128.  
  129.  
  130.     /* copy the temporary bitmap to the screen */
  131.     {
  132.         int h_scroll_num = 0, v_scroll_num = 0;
  133.         int h_scroll[32], v_scroll[32];
  134.  
  135.         if (jackal_videoctrl[2] & 0x08)
  136.         {
  137.             h_scroll_num = 32;
  138.             for (i = 0;i < 32;i++)
  139.                 h_scroll[i] = -(jackal_scrollram[i]);
  140.         }
  141.  
  142.         if (jackal_videoctrl[2] & 0x04)
  143.         {
  144.             v_scroll_num = 32;
  145.             for (i = 0;i < 32;i++)
  146.                 v_scroll[i] = -(jackal_scrollram[i]);
  147.         }
  148.  
  149.         if (jackal_videoctrl[0] != 0)
  150.         {
  151.             v_scroll_num = 1;
  152.             v_scroll[0] = -(jackal_videoctrl[0]);
  153.         }
  154.  
  155.         if (jackal_videoctrl[1] != 0)
  156.         {
  157.             h_scroll_num = 1;
  158.             h_scroll[0] = -(jackal_videoctrl[1]);
  159.         }
  160.  
  161.         if ((h_scroll_num == 0) && (v_scroll_num == 0))
  162.             copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  163.         else
  164.             copyscrollbitmap(bitmap,tmpbitmap,h_scroll_num,h_scroll,v_scroll_num,v_scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  165.     }
  166.  
  167.     /* Draw the sprites. */
  168.     {
  169.         unsigned char sr1, sr2, sr3, sr4, sr5;
  170.         int spritenum, sx, sy, color;
  171.         unsigned char sn1, sn2, sp, flipx, flipy;
  172.  
  173.         for ( offs = 0; offs < 0x0F5; /* offs += 5 */ )
  174.         {
  175.             sn1 = ss[offs++]; // offs+0
  176.             sn2 = ss[offs++]; // offs+1
  177.             sy  = ss[offs++]; // offs+2
  178.             sx  = ss[offs++]; // offs+3
  179.             sp  = ss[offs++]; // offs+4
  180.  
  181.             flipx = sp & 0x20;
  182.             flipy = sp & 0x40;
  183.             color = ((sn2 & 0xf0)>>4);
  184.  
  185.             if ( !(sp & 0xC) )
  186.             {
  187.                 spritenum = sn1 + ((sn2 & 0x3) << 8);
  188.  
  189.                 if (sy > 0xF0) sy = sy - 256;
  190.                 if (sp & 0x01) sx = sx - 256;
  191.  
  192.                 if (sp & 0x10)
  193.                 {
  194.                     if ( (sx > -16) || (sx < 0xF0) )
  195.                     {
  196.                         drawgfx(bitmap,Machine->gfx[2],
  197.                             spritenum,
  198.                             color,
  199.                             flipx,flipy,
  200.                             flipx?sx+16:sx, flipy?sy+16:sy,
  201.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  202.                         drawgfx(bitmap,Machine->gfx[2],
  203.                             spritenum+1,
  204.                             color,
  205.                             flipx,flipy,
  206.                             flipx?sx:sx+16, flipy?sy+16:sy,
  207.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  208.                         drawgfx(bitmap,Machine->gfx[2],
  209.                             spritenum+2,
  210.                             color,
  211.                             flipx,flipy,
  212.                             flipx?sx+16:sx, flipy?sy:sy+16,
  213.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  214.                         drawgfx(bitmap,Machine->gfx[2],
  215.                             spritenum+3,
  216.                             color,
  217.                             flipx,flipy,
  218.                             flipx?sx:sx+16, flipy?sy:sy+16,
  219.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  220.                     }
  221.                 }
  222.                 else
  223.                 {
  224.                     if ( (sx > -8) || (sx < 0xF0) )
  225.                     {
  226.                         drawgfx(bitmap,Machine->gfx[2],
  227.                             spritenum,
  228.                             color,
  229.                             flipx,flipy,
  230.                             sx,sy,
  231.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  232.                     }
  233.                 }
  234.             }
  235.             else if ( (sx < 0xF0) && !(sp & 0x01) )
  236.             {
  237.                 spritenum = sn1*4 + ((sn2 & (8+4)) >> 2) + ((sn2 & (2+1)) << 10);
  238.  
  239.                 if ((sp & 0x0C) == 0x0C)
  240.                 {
  241.                     drawgfx(bitmap,Machine->gfx[4],
  242.                         spritenum,
  243.                         color,
  244.                         flipx,flipy,
  245.                         sx,sy,
  246.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  247.                 }
  248.                 if ((sp & 0x0C) == 0x08)
  249.                 {
  250.                     drawgfx(bitmap,Machine->gfx[4],
  251.                         spritenum,
  252.                         color,
  253.                         flipx,flipy,
  254.                         sx,sy,
  255.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  256.                     drawgfx(bitmap,Machine->gfx[4],
  257.                         spritenum - 2,
  258.                         color,
  259.                         flipx,flipy,
  260.                         sx,sy+8,
  261.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  262.                 }
  263.                 if ((sp & 0x0C) == 0x04)
  264.                 {
  265.                     drawgfx(bitmap,Machine->gfx[4],
  266.                         spritenum,
  267.                         color,
  268.                         flipx,flipy,
  269.                         sx,sy,
  270.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  271.                     drawgfx(bitmap,Machine->gfx[4],
  272.                         spritenum + 1,
  273.                         color,
  274.                         flipx,flipy,
  275.                         sx+8,sy,
  276.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  277.                 }
  278.             }
  279.         }
  280.  
  281.         for (offs = 0; offs < 0x11D; offs += 5)
  282.         {
  283.             if ( (sr[offs+2] < 0xF0) && !(sr[offs+4] & 0x01) )
  284.             {
  285.                 sr1 = sr[offs];
  286.                 sr2 = sr[offs+1];
  287.                 sr3 = sr[offs+2];
  288.                 sr4 = sr[offs+3];
  289.                 sr5 = sr[offs+4];
  290.  
  291.                 sy = sr3;
  292.                 sx = sr4;
  293.  
  294.                 flipx = sr5 & 0x20;
  295.                 flipy = sr5 & 0x40;
  296.                 color = ((sr2 & 0xf0)>>4);
  297.  
  298.                 spritenum = sr1 + ((sr2 & 0x3) << 8);
  299.  
  300.                 if (sr5 & 0xC)    /* half sized sprite */
  301.                 {
  302.  
  303.                     spritenum = sr1*4 + ((sr2 & (8+4)) >> 2) + ((sr2 & (2+1)) << 10);
  304.  
  305.                     if ((sr5 & 0x0C) == 0x0C)
  306.                     {
  307.                         drawgfx(bitmap,Machine->gfx[3],
  308.                             spritenum,
  309.                             color,
  310.                             flipx,flipy,
  311.                             sx,sy,
  312.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  313.                     }
  314.                     if ((sr5 & 0x0C) == 0x08)
  315.                     {
  316.                         drawgfx(bitmap,Machine->gfx[3],
  317.                             spritenum,
  318.                             color,
  319.                             flipx,flipy,
  320.                             sx,sy,
  321.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  322.                         drawgfx(bitmap,Machine->gfx[3],
  323.                             spritenum - 2,
  324.                             color,
  325.                             flipx,flipy,
  326.                             sx,sy+8,
  327.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  328.                     }
  329.                     if ((sr5 & 0x0C) == 0x04)
  330.                     {
  331.                         drawgfx(bitmap,Machine->gfx[3],
  332.                             spritenum,
  333.                             color,
  334.                             flipx,flipy,
  335.                             sx,sy,
  336.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  337.                         drawgfx(bitmap,Machine->gfx[3],
  338.                             spritenum + 1,
  339.                             color,
  340.                             flipx,flipy,
  341.                             sx+8,sy,
  342.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  343.                     }
  344.  
  345.                 }
  346.                 else
  347.                 {
  348.                     if (sr5 & 0x10)
  349.                     {
  350.                         drawgfx(bitmap,Machine->gfx[1],
  351.                             spritenum,
  352.                             color,
  353.                             flipx,flipy,
  354.                             flipx?sx+16:sx, flipy?sy+16:sy,
  355.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  356.                         drawgfx(bitmap,Machine->gfx[1],
  357.                             spritenum+1,
  358.                             color,
  359.                             flipx,flipy,
  360.                             flipx?sx:sx+16, flipy?sy+16:sy,
  361.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  362.                         drawgfx(bitmap,Machine->gfx[1],
  363.                             spritenum+2,
  364.                             color,
  365.                             flipx,flipy,
  366.                             flipx?sx+16:sx, flipy?sy:sy+16,
  367.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  368.                         drawgfx(bitmap,Machine->gfx[1],
  369.                             spritenum+3,
  370.                             color,
  371.                             flipx,flipy,
  372.                             flipx?sx:sx+16, flipy?sy:sy+16,
  373.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  374.                     }
  375.                     else
  376.                         drawgfx(bitmap,Machine->gfx[1],
  377.                             spritenum,
  378.                             color,
  379.                             flipx,flipy,
  380.                             sx,sy,
  381.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  382.                 }
  383.             }
  384.         }
  385.  
  386.         for (offs = 0x4F1; offs >= 0x11D; offs -= 5)
  387.         {
  388.             if ( (sr[offs+2] < 0xF0) && !(sr[offs+4] & 0x01) )
  389.             {
  390.                 sr1 = sr[offs];
  391.                 sr2 = sr[offs+1];
  392.                 sr3 = sr[offs+2];
  393.                 sr4 = sr[offs+3];
  394.                 sr5 = sr[offs+4];
  395.  
  396.                 sy = sr3;
  397.                 sx = sr4;
  398.  
  399.                 flipx = sr5 & 0x20;
  400.                 flipy = sr5 & 0x40;
  401.                 color = ((sr2 & 0xf0)>>4);
  402.  
  403.                 if (sr[offs+4] & 0xC)    /* half sized sprite */
  404.                 {
  405.  
  406.                     spritenum = sr1*4 + ((sr2 & (8+4)) >> 2) + ((sr2 & (2+1)) << 10);
  407.  
  408.                     if ((sr5 & 0x0C) == 0x0C)
  409.                     {
  410.                         drawgfx(bitmap,Machine->gfx[3],
  411.                             spritenum,
  412.                             color,
  413.                             flipx,flipy,
  414.                             sx,sy,
  415.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  416.                     }
  417.                     if ((sr5 & 0x0C) == 0x08)
  418.                     {
  419.                         drawgfx(bitmap,Machine->gfx[3],
  420.                             spritenum,
  421.                             color,
  422.                             flipx,flipy,
  423.                             sx,sy,
  424.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  425.                         drawgfx(bitmap,Machine->gfx[3],
  426.                             spritenum - 2,
  427.                             color,
  428.                             flipx,flipy,
  429.                             sx,sy+8,
  430.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  431.                     }
  432.                     if ((sr5 & 0x0C) == 0x04)
  433.                     {
  434.                         drawgfx(bitmap,Machine->gfx[3],
  435.                             spritenum,
  436.                             color,
  437.                             flipx,flipy,
  438.                             sx,sy,
  439.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  440.                         drawgfx(bitmap,Machine->gfx[3],
  441.                             spritenum + 1,
  442.                             color,
  443.                             flipx,flipy,
  444.                             sx+8,sy,
  445.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  446.                     }
  447.  
  448.                 }
  449.                 else
  450.                 {
  451.                     spritenum = sr1 + ((sr2 & 0x3) << 8);
  452.  
  453.                     if (sr5 & 0x10)
  454.                     {
  455.                         drawgfx(bitmap,Machine->gfx[1],
  456.                             spritenum,
  457.                             color,
  458.                             flipx,flipy,
  459.                             flipx?sx+16:sx, flipy?sy+16:sy,
  460.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  461.                         drawgfx(bitmap,Machine->gfx[1],
  462.                             spritenum+1,
  463.                             color,
  464.                             flipx,flipy,
  465.                             flipx?sx:sx+16, flipy?sy+16:sy,
  466.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  467.                         drawgfx(bitmap,Machine->gfx[1],
  468.                             spritenum+2,
  469.                             color,
  470.                             flipx,flipy,
  471.                             flipx?sx+16:sx, flipy?sy:sy+16,
  472.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  473.                         drawgfx(bitmap,Machine->gfx[1],
  474.                             spritenum+3,
  475.                             color,
  476.                             flipx,flipy,
  477.                             flipx?sx:sx+16, flipy?sy:sy+16,
  478.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  479.                     }
  480.                     else
  481.                         drawgfx(bitmap,Machine->gfx[1],
  482.                             spritenum,
  483.                             color,
  484.                             flipx,flipy,
  485.                             sx,sy,
  486.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  487.                 }
  488.             }
  489.         }
  490.     }
  491. }
  492.